package P1线性结构.LeetCode双指针;

public class LeetCode2181 {
    public ListNode mergeNodes(ListNode head) {
        ListNode dummy = new ListNode();
        ListNode rear = dummy;
        ListNode L = head;
        ListNode R = L.next;
        int sum = 0;    //某一个区间的总和
        while (R != null) {
            if (R.val == 0) {
                ListNode node = new ListNode(sum);
                rear.next = node;
                rear = rear.next;
                sum = 0;
                L = R;
                R = L.next;
            } else {
                sum += R.val;
                R = R.next;
            }
        }
        return dummy.next;
    }
}
